﻿namespace DBUtility
{
    public class DBHelperFactory
    {
        /// <summary>
        /// 获取一个IDBHelper对象
        /// </summary>
        public static IDBHelper CreateInstance()
        {
            IDBHelper _iDBHelper;
            string dbType = System.Configuration.ConfigurationManager.ConnectionStrings["ConString"].ProviderName.Trim();
            switch (dbType)
            {
                case "MySql.Data.MySqlClient":
                    _iDBHelper = new MySqlDBHelper();
                    break;
                case "System.Data.SqlClient":
                    _iDBHelper = new SqlDBHelper();
                    break;
                case "System.Data.OracleClient":
                    _iDBHelper = new OracleDBHelper();
                    break;
                case "System.Data.OleDb":
                    _iDBHelper = new OleDBHelper();
                    break;
                //========还可以写Access数据库的类似MySqlDBHelper和SqlDBHelper的访问类，等等===========
                default:
                    _iDBHelper = new MySqlDBHelper();
                    break;
            }
            return _iDBHelper;
        }      
    }
}
